package com.itheima.service.db.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.domain.db.PageBeanVo;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findByPage(Integer pageNum, Integer pageSize, Long userId) {

        Page<BlackList> page = new Page<>();

        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("user_id", userId);

        page = blackListMapper.selectPage(page, queryWrapper);

        return new PageBeanVo(pageNum, pageSize, page.getTotal(), page.getRecords());
    }

    @Override
    public void delete(Long userId, Long blackUserId) {

        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("user_id", userId);

        queryWrapper.eq("black_user_id", blackUserId);

        blackListMapper.delete(queryWrapper);
    }
}
